#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2022, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: 剑指 Offer 09. 用两个栈实现队列.py
@time: 2022/3/6 21:54
@desc: https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
'''
class CQueue:

    def __init__(self):
        self.head = []
        self.tail = []

    def appendTail(self, value: int) -> None:
        if self.tail: self.tail.append(value)
        else:
            while self.head:
                self.tail.append(self.head.pop())
            self.tail.append(value)


    def deleteHead(self) -> int:
        if self.head: return self.head.pop()
        else:
            if not self.tail: return -1
            while self.tail:
                self.head.append(self.tail.pop())
            return self.head.pop()



# Your CQueue object will be instantiated and called as such:
p1 = obj = CQueue()
p2 = obj.appendTail(3)
param_2 = obj.deleteHead()
param_3 = obj.deleteHead()
param_4 = obj.deleteHead()
print(p1, p2, param_2, param_3, param_4)
